{include_core file="m/lib/header.html" title="注册NBD账号"}
<div class="associated-page">
	<div class="register associate3">
	    <!-- <div class="header">
	      <h2>注册NBD账号</h2>
	    </div> -->
	    <form action = "{AnUrl('openapi/index/create_user')}" method="post" id="js_register_m">
		    <div class="input-box">
    		  <p class="txt-wrap"><input type="text" placeholder="用户名" name="username" id="js_usernameM"/></p>
		      <p class="txt-wrap"><input type="text" placeholder="手机号码" name="mobile" id="js_mobileM"/></p>
		      <p class="txt-wrap"><input type="text" placeholder="验证码" name="code" id="js_codeM"/><a href="javascript:void(0);" id="getCode" value="on" class="get-btn">获取验证码</a></p>
		      <div class="bottom clearfix"><label><input type="checkbox" id="isRead" checked>我已阅读并接受《NBD服务协议条款》</label><a href="{AnUrl('openapi/bind')}" class="hased">已有账号</a></div>
		      <div class="btns"><a href="javascript:void(0);" id="register-mobile" class="btn ">提交</a></div>
		    </div>
		</form>
	  </div>
	</div>
</div>
<script>
$(function(){

  var user_off = mobile_off = code_off  = 1;
  
  $('#js_usernameM').blur(function(){
    var username = $.trim($(this).val());
    var userLen  = getStringLen(username);
    if(username == '') {
      user_off = 1;
      mobileShowMsg('您输入的用户名不能为空');
      return ;
    }
    if(checkStr(username, 'mail')) {
      user_off = 1;
      mobileShowMsg('您输入的用户名不能为邮箱！');
      return ;
    }
    if(userLen < 6 || userLen > 20) {
      user_off = 1;
      mobileShowMsg('用户名应在6个到20个字符之间');
      return ;
    }
    if(!checkStr(username, 'name')) {
      user_off = 1;
      mobileShowMsg('您输入的用户名格式不正确');
      return ;
    }
    if(is_number(username)) {
      user_off = 1;
      mobileShowMsg('用户名不能为纯数字');
      return ;
    }
    $.post(
        "{AnUrl('user/register/ajax_username')}",
        { username:username },
        function(data){
          if(data.info == 'error') {
            user_off = 1;
            mobileShowMsg(data.msg);
            return;
          } else {
            user_off = 0;
          }
        },'json');
  });

  $('#js_mobileM').blur(function(){
    var mobile = $.trim($(this).val());
    if(mobile == '') {
      mobile_off = 1;
      mobileShowMsg('您输入的手机号不能为空');
      return ;
    }
    if(!checkStr(mobile, 'mobile')) {
      mobile_off = 1;
      mobileShowMsg('您输入的手机号格式不正确');
      return ;
    }
    $.post(
        "{AnUrl('user/register/ajax_mobile')}",
        { mobile:mobile },
        function(data) {
          if(data.info == 'error') {
            mobile_off = 1;
            mobileShowMsg(data.msg);
            return;
          } else {
            mobile_off = 0;
          }
        },'json'
    );
  });

  $('#js_codeM').blur(function(){
    var code = $.trim($(this).val());
    var mobile = $.trim($('#js_mobileM').val());
    if(mobile == '') {
      code_off = 1;
      mobileShowMsg('您输入的手机号不能为空');
      return ;
    }
    if(!checkStr(mobile, 'mobile')) {
      code_off = 1;
      mobileShowMsg('您输入的手机号格式不正确');
      return ;
    }
    if(code == '') {
      code_off = 1;
      mobileShowMsg('您输入的验证码不能为空');
      return ;
    }
    $.post(
        "{AnUrl('user/register/ajax_code')}",
        { code:code, mobile:mobile, code_type:'perfect' },
        function(data) {
          if(data.info == 'error') {
            code_off = 1;
            mobileShowMsg(data.msg);
            return;
          } else {
             code_off = 0;
          }
        },'json'
    );
  })

  $('#register-mobile').click(function(){
    $(this).html('正在提交...');
    $('#js_usernameM').trigger('blur');
    $('#js_mobileM').trigger('blur');
    $('#js_codeM').trigger('blur');
    if(user_off == 0 && mobile_off == 0 && 0 == code_off) {
    	if(!$('#isRead').is(':checked')) {
	      mobileShowMsg('请先同意《NBD服务协议条款》！');
	      return ;
	    }
      $('#js_register_m').submit();
    } else {
      $(this).html('提交');
    }
  });
//获取验证码
  $('#getCode').click(function(){
    var mobile = $.trim($('#js_mobileM').val());
    $('#js_usernameM').trigger('blur');
    $('#js_mobileM').trigger('blur');
    var codeNext = $('#js_codeM').next();
    if(user_off == 0 && mobile_off == 0) {
      if($(this).attr('value') == 'on') {
        var time = 59;
        $('#getCode').html(time).attr('value', 'off');
        var Timer=setInterval(function(){
          if(time > 0){
            time--;
            $('#getCode').html(time).attr('value', 'off');
          } else {
            $('#getCode').html('获取').attr('value', 'on');
            clearInterval(Timer);
          }
        },1000);
      $.post(
          "{AnUrl('user/register/sendRegsms')}",
          { 'mobile':mobile, 'send_type':'perfect' },
          function(data){
            if(data.info == 'error') {
              mobileShowMsg(data.msg);
            }
          },'json');
      }
    }
  });
});
</script>
{include_core file="m/lib/footer.html"}